home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 October / CHIP Ekim 1996.iso / winbatch / problem.wb_ < prev    next >
Text File  |  1994-08-31  |  2KB  |  82 lines

  1. a1=  "An unexpected problem can occur when dividing numbers."
  2. a2=  "The problem is in deciding between an integer divide "
  3. a3=  "(where the remainder, if any, is discarded) and a floating "
  4. a4=  "point divide (where a floating point number is returned)."
  5. a5=  ""
  6. a6=  ""
  7. a7=  "Let's assume a test.  There are 42 questions."
  8. a8=  "A student gets 37 of them correct,"
  9. a9=  "what is the student's score."
  10. a10= " "
  11. a11= "iQuestions = 42"
  12. a12= "iCorrect = 37"
  13. a13= "Score = iCorrect / iQuestions"
  14.  
  15. iQuestions = 42
  16. iCorrect = 37
  17. Score = iCorrect / iQuestions
  18.  
  19. a14= " "
  20. a15= "The unexpected result is that the score is %Score%"
  21.  
  22.  
  23. a16= "Reasonable problem?  The trap is that WIL will perform an"
  24. a17= "integer divide and return the unexpected answer of Zero."
  25. a18= " "
  26. a19= "To dig your code out of this trap, simply use floating point"
  27. a20= "numbers when you want a floating point answer."
  28. a21 = " "
  29. a22= "fQuestions = 42.0"
  30. a23= "fCorrect = 37.0"
  31.  
  32. fQuestions = 42.0
  33. fCorrect = 37.0
  34. Score = fCorrect / fQuestions 
  35.  
  36. a24= "Score = fCorrect / fQuestions"
  37. a25= "The correct score  is %Score%"
  38. a26= " "
  39. a27= "Or make the answer look nicer by using the Decimals function"
  40. a28= "and a little formatting."
  41. a29= ""
  42. a30= "Decimals(0)
  43. a31= "Score=Score*100"
  44. Decimals(0)
  45. Score=Score*100
  46. a32= ""
  47. a33= "The correct score  is %Score%%%"
  48.  
  49.  
  50.  
  51.  
  52. text=""
  53. for i=1 to 15
  54.    text=strcat(text,a%i%,@crlf)
  55. next
  56.  
  57. text2=""
  58. for i=16 to 33
  59.    text2=strcat(text2,a%i%,@crlf)
  60. next
  61.  
  62. Message("Integer Divide Problem",text)
  63. Message("Floating point solution",text2)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.    
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.